using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Diagnostics;
using System.Windows.Forms;

using Janus.Windows.GridEX;

namespace Janus.NorthwindDemo2007
{
	public partial class CustomersGridEXView
	{

		protected override void OnFolderViewChanged()
		{
			base.OnFolderViewChanged();
			GridEXLayout layout = this.GridEX.FindLayout(this.FolderView.LayoutName);
			layout.SetDataBinding(this.DataSource, "Customers");

			this.GridEX.CurrentLayout = layout;
			this.FillCountriesValueList();
			//We need to call Refetch method if valuelist or dropdowns are populated
			//after the datasource in the grid is populated
			this.GridEX.Refetch();

			this.EnableCommands();
		}

		private void FillCountriesValueList()
		{
			DataView countries = new DataView(NorthwindApp.NorthwindApplication.GetCountriesTable());
			this.GridEX.RootTable.Columns["Country"].HasValueList = true;
			this.GridEX.RootTable.Columns["Country"].EditType = EditType.Combo;
			this.GridEX.RootTable.Columns["Country"].ColumnType = ColumnType.ImageAndText;
			this.GridEX.RootTable.Columns["Country"].ValueList.PopulateValueList(countries, "Country", "Country", "Flag", Color.Magenta, new Size(19, 13));
		}

		public override void Edit()
		{
			foreach (GridEXSelectedItem item in this.GridEX.SelectedItems)
			{
				if (item.RowType == RowType.Record)
				{
					CustomerDataForm custDialog = new CustomerDataForm();
					custDialog.Edit(((DataRowView)(item.GetRow().DataRow)).Row);
				}
			}
		}
	}

} //end of root namespace